import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JTextField;
import javax.swing.JLabel;
import java.awt.Font;
import javax.swing.JButton;
import javax.swing.JPasswordField;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JOptionPane;

public class Login extends JFrame {

	private JPanel contentPane;
	private String password = "test";
	private JPasswordField passwordField;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					Login frame = new Login();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public Login() {
		super("Login");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 450, 300);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JLabel lblEmats = new JLabel("E - MaTS");
		lblEmats.setFont(new Font("Tahoma", Font.BOLD, 15));
		lblEmats.setBounds(10, 11, 110, 40);
		contentPane.add(lblEmats);
		
		JLabel lblPassword = new JLabel("Password:");
		lblPassword.setBounds(55, 92, 65, 14);
		contentPane.add(lblPassword);
		
		JButton btnNewButton = new JButton("Authenticate");
		btnNewButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				if(Authenticate(passwordField.getText(), password))
					openMemberRoot();
				else;
			}
		});
		btnNewButton.setBounds(253, 156, 137, 83);
		contentPane.add(btnNewButton);
		
		passwordField = new JPasswordField();
		passwordField.setBounds(124, 89, 93, 20);
		contentPane.add(passwordField);
	}
	
	public boolean Authenticate (String key, String password)
	{
		boolean det = false;
		if(key.isEmpty())
			JOptionPane.showMessageDialog(null, "Password Field Empty", "Error", JOptionPane.ERROR_MESSAGE);
		else if (!(key.equals(password)))
			JOptionPane.showMessageDialog(null, "Check Password", "Error", JOptionPane.ERROR_MESSAGE);
		else
			det = true;
			
		return det;
	}
	
	public void openMemberRoot()
	{
		this.dispose();
		MemberRoot mr = new MemberRoot();
		mr.setVisible(true);
	}
	
	
}
